package me.zk.practice1.hw;

import java.util.LinkedList;
import java.util.Scanner;
import java.util.Stack;

/**
 * @author zhangkai
 * @date 2023/8/10 15:00
 */
public class HWBJJ04 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String s1 = scanner.nextLine();
        System.out.println(getStr(s1));
    }

    public static String getStr(String s) {
        LinkedList<String> stack = new LinkedList<>();
        char[] chars = s.toCharArray();
        int index = 0;
        while (index < chars.length) {
            char c = chars[index];
            if (Character.isDigit(c)) {
               StringBuffer sb = new StringBuffer();
               sb.append(c);
                while (Character.isDigit(++index)){
                    sb.append(chars[index]);
                }
                stack.addLast(sb.toString());
            } else if (c == ']' ){
                StringBuffer sb1= new StringBuffer();
                while (!stack.peekLast().equals("[")) {
                    sb1.append(stack.removeLast());
                }
                stack.removeLast();
                int n = Integer.parseInt(stack.removeLast());
                sb1.reverse();
                StringBuffer sb2 = new StringBuffer();
                for (int i = 0; i < n; i++) {
                    sb2.append(sb1);
                }
                stack.addLast(sb2.toString());
                index++;
            } else {
                stack.addLast(String.valueOf(c));
                index++;
            }

        }
        StringBuffer sb = new StringBuffer();
        for (String ss : stack) {
            sb.append(ss);
        }

        return sb.toString();
    }
}
